package ign;

import jade.wrapper.PlatformController.Listener;
import jade.wrapper.PlatformEvent;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;

/**
 * Classe qui s'occupe de compter les agents ajoutés et supprimés dans Jade.
 * @author Simon Bourigaut & Ghislain Di Paolo
 */
public class MyListener implements Listener {

	private long init_time = 0;
	private int nbAgentAlive = 0 ;
	private int nbAgentCreated = 0;
	private int nbAgentDead = 0;
	
	private ArrayList<SimpleEntry<Long, Integer>> data;

	public MyListener() {
		init_time = System.currentTimeMillis();
		data = new ArrayList<SimpleEntry<Long, Integer>>();
	}
	
	@Override
	public void bornAgent(PlatformEvent anEvent) {
		nbAgentAlive++ ;
		nbAgentCreated++;
	}

	@Override
	public void deadAgent(PlatformEvent anEvent) {
		nbAgentAlive-- ;
		nbAgentDead++;
		
		long cur_time = System.currentTimeMillis();
		long abs = cur_time - init_time;
		SimpleEntry<Long, Integer> e = new SimpleEntry<Long, Integer>(abs, nbAgentDead);
		data.add(e);
	}

	@Override
	public void killedPlatform(PlatformEvent anEvent) {
	}

	@Override
	public void resumedPlatform(PlatformEvent anEvent) {
	}

	@Override
	public void startedPlatform(PlatformEvent anEvent) {
	}

	@Override
	public void suspendedPlatform(PlatformEvent anEvent) {
	}
	
	public int getNbAgentAlive() {
		
		return nbAgentAlive ;
	}
	
	public int getNbAgentCreated(){
		
		return nbAgentCreated;
	}
	
	public ArrayList<SimpleEntry<Long, Integer>> getData(){
		return data;
	}
}
